#light

namespace Demos.WshScripting

#r @"webtools.core.dll"
open System
open FSharp.WebTools

(*-----------------------------------------------------------------------------------------------*)

type ShellProcess = 
  [<Mapping("Status", MappingScope.Member, MappingType.Field)>]
  member x.Status : int = raise ClientSideScript

type Shell = 
  [<Mapping("WScript.CreateObject(\"WScript.Shell\")", MappingScope.Global, MappingType.Inline)>]
  static member Current : Shell = raise ClientSideScript 

  [<Mapping("Exec", MappingScope.Member, MappingType.Method)>]
  member x.Exec(s:string) : ShellProcess = raise ClientSideScript

  [<Mapping("Popup", MappingScope.Member, MappingType.Method)>]
  member x.Popup(message:string, i:int, title:string, i2:int) : int = raise ClientSideScript

type InStream = 
  [<Mapping("ReadLine", MappingScope.Member, MappingType.Method)>]
  member x.ReadLine () : string = raise ClientSideScript
  
  [<Mapping("AtOfStream", MappingScope.Member, MappingType.Field)>]
  static member EOF : bool = raise ClientSideScript

type OutStream = 
  [<Mapping("WriteLine", MappingScope.Member, MappingType.Method)>]
  member x.WriteLine(s:string) : unit = raise ClientSideScript

[<Mapping("WScript", MappingScope.Global, MappingType.Inline)>]
type Script = 
  [<Mapping("Sleep", MappingScope.Member, MappingType.Method)>]
  static member Sleep (msecs:int) : unit = raise ClientSideScript
  
  [<Mapping("Echo", MappingScope.Member, MappingType.Method)>]
  static member Echo (s:string) : unit = raise ClientSideScript

  [<Mapping("StdIn", MappingScope.Member, MappingType.Field)>]
  static member In : InStream = raise ClientSideScript

  [<Mapping("StdOut", MappingScope.Member, MappingType.Field)>]
  static member Out : OutStream = raise ClientSideScript

[<ClientSide; ExternalType(type System.Console)>]
type Console = 
  [<ReflectedDefinition>]
  static member WriteLine(s) =
    Script.Out.WriteLine(s)
  
  [<ReflectedDefinition>]
  static member ReadLine() =
    Script.In.ReadLine()    